package com.eascs.web.o2o.scheduler.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.web.o2o.scheduler.dao.BaseDao;
import com.eascs.web.o2o.scheduler.history.BaseService;

@Service
public class SynoInfoService extends BaseService {
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Inject
	BaseDao baseDao;
	
	public void save(String name, int flag){
		int count = countTodaySynoInfo(name, 1);
		if(count > 0){
			logger.info("================[{}]数据抽取任务已经同步成功过一次================", name);
			return;
		}
		baseDao.excuteSql("insert into syno_info(syno_data,syno_date,syno_status) values(?,sysdate(),?)",name,flag);
		logger.info("================[{}]数据抽取任务[{}]================", name, flag==1?"成功":"失败");
	}
	
	public int countTodaySynoInfo(String name, int flag){
		List<Object[]> list= baseDao.findObjectsList("select * from syno_info where syno_data = '" + name + "' and syno_date = date_format(sysdate(),'%Y-%m-%d') and syno_status = " + flag);
		return list.size();
	}
}
